#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File  :logger.py
# Time  :2024/11/26 16:28
# Email :fortunatedong@163.com
# Author:by Adonli
import sys

from loguru import logger

folder_ = "Log/"
rotation_ = "00:00"
retention_ = "30 days"
encoding_ = "utf-8"
backtrace_ = True
diagnose_ = False
enqueue_=True
format_ = '<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> ' \
            '| <magenta>{process}</magenta>:<yellow>{thread}</yellow> ' \
            '| <cyan>{name}</cyan>:<cyan>{function}</cyan>:<yellow>{line}</yellow> - <level>{message}</level>'
class Loggings():
    __instance = None
    # _initialized = False
    logger.remove()
    logger.add(folder_ + "guotiejingdongprice.log", backtrace=backtrace_, diagnose=diagnose_,
               format=format_, colorize=False,
               rotation=rotation_, retention=retention_, encoding=encoding_,enqueue=enqueue_)
    # 添加控制台处理程序
    logger.add(
        sys.stderr,
        format=format_,
        colorize=True,
        backtrace=backtrace_,
        diagnose=diagnose_,
        enqueue=enqueue_
    )

    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super(Loggings, cls).__new__(cls, *args, **kwargs)

        return cls.__instance
    def info(self, msg):
        return logger.info(msg)

    def debug(self, msg):
        return logger.debug(msg)

    def warning(self, msg):
        return logger.warning(msg)

    def error(self, msg):
        return logger.error(msg)